package com.upb.webserver.datafetcher;

import com.upb.webserver.common.pojo.base.BasePageResponse;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * request data from data-fetcher merge.
 *
 */
@Log4j2
@RestController
@RequestMapping(value = "data-fetcher")
public class DataFetcherController {

    @Autowired
    private DataFetcherService dataFetcherService;

    /**
     * get chain list.
     */
    @GetMapping("chain/list")
    public BasePageResponse getChainList() {
        log.info("data-fetcher getChainList.");
        return dataFetcherService.getChainList();
    }
    
    /**
     * search data by keyword.
     * 
     * @param pageNumber
     * @param pageSize
     * @param keyword
     * @return
     */
    @GetMapping("search/keyword/{pageNumber}/{pageSize}")
    public BasePageResponse searchByKeyword(@PathVariable("pageNumber") Integer pageNumber,
            @PathVariable("pageSize") Integer pageSize,
            @RequestParam(value = "keyword", required = true) String keyword) {
        log.info("data-fetcher searchByKeyword.");
        return dataFetcherService.searchByKeyword(pageNumber, pageSize, keyword);
    }
}
